home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7610 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.8 KB  |  90 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!marnold
  3. From: marnold@netcom.com (Matt Arnold)
  4. Subject: Re: Is there a standard for * and & placement style?
  5. Message-ID: <marnoldDn9u0A.GAD@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. References: <3128BD31.4AF8@wildfire.com> <marnoldDn27q9.Is0@netcom.com> <4gckd5$bc7@clarknet.clark.net> <marnoldDn63vB.H6n@netcom.com> <4gk1b8$mtm@werple.net.au>
  8. Date: Sat, 24 Feb 1996 08:24:10 GMT
  9. Sender: marnold@netcom20.netcom.com
  10.  
  11. davidw@werple.net.au (David White) writes:
  12.  
  13. >marnold@netcom.com (Matt Arnold) writes:
  14.  
  15. >>gusty@clark.net (Harlan Messinger) writes:
  16.  
  17. >>>I think the syntax is dumb in the first place. One declaration statement 
  18. >>>should declare variables of one type. I think
  19.  
  20. >>>    char* a, b, c;
  21.  
  22. >>>should declare three (char*) variables. If someone also wants a char 
  23. >>>variable d, then that should be on two lines:
  24.  
  25. >>That would be better, but I still subscribe to the "one concept per
  26. >>line" theory of programming and would never declare three variables on
  27. >>a single line.  
  28.  
  29. >The concept used in declarations is that a declaration mimics an
  30. >expression, e.g., given char *p, if you see *p then it evaluates to a
  31. >char. The above form is therefore a special case because it can't always
  32. >be used. In the case of, for example, char (*p)[10], you can't apply it. 
  33. >I can see that in the trivial special cases, like char* foo(), it seems
  34. >more sensible to some people (foo() returns a char*), but it is an oddity
  35. >in terms of the general rule. 
  36.  
  37. Hmm, thinking of function foo() as "returning a char*" doesn't seem to me 
  38. to be any more a special case than thinking of p as "_being_ a char*".
  39.  
  40. I still think pointer-ness or reference-ness is better associated with the 
  41. type.  When I see "p" (from your example) in some code, I think of it as 
  42. being type "char*", and that is the way I declare it.
  43.  
  44. In fact, I'd argue that the fact that a function declaration such as...
  45.  
  46.    char* foo();
  47.  
  48. ...is a "special case" for the "char *"-style, simply highlights that the
  49. style, IMO, is conceptually inconsistent.  Certainly, the function itself 
  50. doens't have pointer-ness (although, as for as the language it concerned, it 
  51. resovles to an expression that does) and so it doesn't seem quite right to 
  52. associate the * with the function name.  It seems inconsistent that you 
  53. would make this concession, but turn around and insist the "char *p" makes 
  54. sense for the declaration of p.
  55.  
  56. I have never had any inconsistencies like this with the "char*"-style.  It 
  57. even, to me, resolves nicely with the fact that you can typedef a "char 
  58. pointer type", PCHAR say, and substitute it for all the char*'s throughout 
  59. the code, whether they be found in casts or declarations or function return 
  60. types. 
  61.  
  62. I don't think there any magic in the fact that C/C++ declarations look 
  63. like expressions.  What if, for example, one declared pointer variables 
  64. using a symbol completely different than for dereferencing?
  65.  
  66.    char@ p = // alloc storage to put char "at"
  67.  
  68.    *p = 'x'
  69.  
  70. It would still make sense to me to think of p's type as "char@", which
  71. after all *is* its type. 
  72.  
  73.  
  74. I guess it all depends on where you imagine pointer-ness residing:  "in"
  75. the variable, or "in" the type.  To me it makes more sense, and actually
  76. is correct, to think of pointer-ness as a being part of type (we all know
  77. this is how compilers work).  I therefore prefer to write "char* p", not 
  78. "char *p".
  79.  
  80.  
  81. -------------------------------------------------------------------------
  82. Matt Arnold                       |        | ||| | |||| |  | | || ||
  83. marnold@netcom.com                |        | ||| | |||| |  | | || ||
  84. Boston, MA                        |      0 | ||| | |||| |  | | || ||
  85. 617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
  86. C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
  87. -------------------------------------------------------------------------
  88.  
  89.  
  90.